<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<script>
  function sortArray(array, type = 'asc') {
    return array.sort((a, b) => (type == 'asc' ? a - b : b - a));
  }

  let arr = [2, 4, 1, 3, 6]
  console.log(sortArray(arr))

  // 默认参数要放在后面，避免引起赋值冲突
  function sum(total, discount = 0, dis = 0) {
    return total * (1 - discount) * (1 - dis)
  }

  console.log(sum(1000))

  //
  function add(...args) {
    return args.reduce((a, b) => a + b)
  }

  console.log(add(1, 2, 3, 4, 5))
</script>
</body>
</html>